<?php

namespace Admin\Controller;
use Admin\Controller\AdminController;
use Admin\Model\CommentModel;
class CommentController extends AdminController
{
    //显示所有评论$this->checkPower();
    public function index ()
    {
        $this->checkPower();
        //根据评论人姓名搜索
        $name = "";
        if(!empty($_GET['name'])){
            $name = I("get.name");
        }

        //根据评论发布时间搜索
        $time= "";
        if(!empty($_GET['time'])){
            $time = I("get.time");
        }
        //根据评论是否显示搜索
        $is_show = "";
        if(!empty($_GET['is_show'])){
            $is_show = I("get.is_show");
        }
        $data['name'] = $name;
        $data['time'] = $time;
        $data['is_show'] = $is_show;

        //排序字段
        $order = "";
        if(!empty($_GET['order'])){
            $order = I("get.order");
        }
        //排序方式
        $order1 = "";
        if(!empty($_GET['order1'])){
            $order1 = I("get.order1");
        }
        $data['order'] = $order;
        $data['order1'] = $order1;

        $this->title = "评论列表";
        $comm = new CommentModel();
        $res = $comm->queryAllComment($data);
        $this->comList = $res['list'];
        $this->page = $res['show'];
        $this->display("Comment/index");
    }

    //更改评论是否显示
    public function isShow ()
    {

        $id = I("get.id");
        $is_show = I("get.show") == 0 ? 1 : 0;
        $com = new CommentModel();
        $com->updateShow($id,$is_show);
        $this->redirect("Comment/index");
    }

    //评论内容详情
    public function queryComInfo ()
    {
        $id = I("get.id");
        $this->title = "评论内容详情";
        $art = new CommentModel();
        $info = $art->queryComInfoById($id);
        $this->info = $info;
        $this->display("Comment/commentDetail");
    }

    //删除评论内容
    public function deleteCom ()
    {
        $id = I("get.id");
        $com = new CommentModel();
        $com->deleteCom($id);
        $this->redirect("Comment/index");
    }

    //删除评论内容$this->checkPower();
    public function deleteComm ()
    {
        $this->checkPower();
        $id = I("get.id");
        $com = new CommentModel();
        $com->deleteCom($id);
    }
}